﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HQDBF;
using System.IO;

namespace WinCurrentPrice
{
    public partial class frmNewMain : Form
    {
        public frmNewMain()
        {
            InitializeComponent();
        }

        public class Stock
        {
            public int 代码 { get; set; }
            public string 名称 { get; set; }
            public double 价格 { get; set; }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<Stock> stocks = new List<Stock>();
            List<string> codes = new List<string>();

            //加载沪深300股票
            using (StreamReader vStreamReader = new StreamReader(Application.StartupPath + "\\Data\\Csi300ConsList.txt", Encoding.Default))
            {
                string vLine;
                while ((vLine = vStreamReader.ReadLine()) != null)
                {
                    stocks.Add(new Stock()
                    {
                        代码 = Convert.ToInt32(vLine.Substring(0, 6)),
                        名称 = vLine.Substring(7).Trim()
                    });
                    codes.Add(vLine.Substring(0, 6));
                }
            }

            PriceQuery query=new PriceQuery();
            double[] result = query.GetSellPricesX(codes.ToArray(), 1);

            for (int i = 0; i < result.Length; i++)
            {
                stocks[i].价格 = result[i];
            }

            this.dataGridView1.DataSource = stocks;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            PriceQuery query = new PriceQuery();
            MessageBox.Show(query.GetHS300ZJCJ().ToString());
        }

        private void button3_Click(object sender, EventArgs e)
        {
            List<string> codes = new List<string>();

            //加载沪深300股票
            using (StreamReader vStreamReader = new StreamReader(Application.StartupPath + "\\Data\\Csi300ConsList.txt", Encoding.Default))
            {
                string vLine;
                while ((vLine = vStreamReader.ReadLine()) != null)
                {
                    codes.Add(vLine.Substring(0, 6));
                }
            }

            PriceQuery query = new PriceQuery();
            this.dataGridView1.DataSource = query.GetBuyPricesXWithAmount(codes.ToArray(), 1);
        }
    }
}
